import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/21 9:27
 * @description 计数数组
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    public String frequencySort(String s) {
        int[] cnt = new int[128];
        for(char c: s.toCharArray()) {
            cnt[c]++;
        }
        int[][] sort = new int[128][1];
        for (int i = 0; i < 128; i++) {
            if (cnt[i] > 0) {
                sort[i][0] = cnt[i];
                sort[i][0] = i;
            }
        }
        Arrays.sort(sort, (a, b)-> b[0] - a[0]);
        StringBuffer sb = new StringBuffer();
        for(int i = 0; i < 128; i++) {
            if (sort[i][0] == 0) {
                break;
            }
            for(int j = 0; j < sort[i][0]; j++) {
                sb.append((char) sort[i][1]);
            }
        }
        return sb.toString();
    }
}
